home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
PROGRAMM
/
CC_C
/
0924.ZIP
/
HDUMP
< prev
next >
Wrap
Text File
|
1988-01-10
|
3KB
|
95 lines
/* ----- C PROGRAM FOR FILE DUMP -----
Command Line: HDUMP FILENAME \n
*/
/* Standard IO definitions */
#define NULL 0
#define EOF -1
#define ERROR -1
/* IO buffer size */
#define qbsize 8192
/* Global output line buffer */
char line[80], *ptr;
/* Read and dump file */
main (argc, argv) int argc; int *argv;
{ static int i, c, d, r, cc[16];
static unsigned ic;
static char *afile;
static char *qnx, *qnd; static int qfd;
static char qbb [qbsize];
putstr ("\n C FILE DUMP PROGRAM\n\n");
if (argc < 2)
{ putstr (" NO FILE SPECIFIED.\n"); return; }
if ( (qfd = open (afile = *++argv, 0)) == ERROR)
{ putstr (" CANNOT OPEN FILE ");
putstr (afile); putstr ("\n"); return; }
for (qnx = qnd = qbb, ic = 0x100; ; ic++)
{
if (qnx < qnd) c = *qnx++;
else { qnd = qbb + read (qfd, qbb, qbsize);
c = ((qnx = qbb) < qnd) ? *qnx++ : EOF; }
cc [r = ic % 16] = c;
if (r == 0)
{ if (c == EOF) break; ptr = line; sp (2);
hex (ic >> 8); hex (ic & 0xFF); sp (1); }
if (c == EOF) sp (3);
else { *ptr++ = (r == 8) ? '-' : ' '; hex (c); }
if ( r == 15)
{ sp (2);
for (i = 0; i < 16; i++)
{ if ((d = cc[i]) == EOF) sp (1);
else *ptr++ = (d < 0x20 || d > 0x7F) ? '.' : d; }
*ptr++ = '\n'; *ptr = 0; putstr (line); }
}
close (qfd); }
hex (n) unsigned n; { dig (n >> 4); dig (n & 0xF); }
dig (n) unsigned n; { *ptr++ = '0' + n + (n > 9 ? 7 : 0); }
sp (n) { while (n--) *ptr++ = ' '; }
/* File and Console Input/Output */
/* Put string to stdout - MSDOS Fn 6 except for \n. */
putstr (s) char *s;
{ inline ( 0x89, 0xE5, 0x8B, 0x7E, 0x02, 0x31, 0xDB,
0x8A, 0x05, 0x47, 0x08, 0xC0, 0x74, 0x1B,
0x43, 0x3C, 0x0A, 0x74, 0x08, 0x88,
0xC2, 0xB4, 0x06, 0xCD, 0x21, 0xEB, 0xEC,
0xB2, 0x0D, 0xB4, 0x02, 0xCD, 0x21,
0xB2, 0x0A, 0xB4, 0x02, 0xCD, 0x21, 0xEB, 0xDE ); }
open (name, mode) char *name;
{ /* Modes 0 read, 1 write, 2 r/w */
inline ( 0x89, 0xE5, 0x8B, 0x56, 0x04, 0x8A, 0x46, 0x02,
0xB4, 0x3D, 0xCD, 0x21, 0x89, 0xC3,
0x73, 0x03, 0xBB, 0xFF, 0xFF ); }
close (fd)
{ inline ( 0x89, 0xE5, 0x8B, 0x5E, 0x02,
0xB4, 0x3E, 0xCD, 0x21, 0xBB, 0x00, 0x00,
0x73, 0x03, 0xBB, 0xFF, 0xFF ); }
read (fd, buf, ct) char *buf;
/* returns #read, else 0 EOF or -1 error */
{ inline ( 0x89, 0xE5, 0x8B, 0x5E, 0x06,
0x8B, 0x56, 0x04, 0x8B, 0x4E, 0x02,
0xB4, 0x3F, 0xCD, 0x21, 0x89, 0xC3,
0x73, 0x03, 0xBB, 0xFF, 0xFF ); }
/* End of dump file program */